home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / BBS / MUBBS / MUBBS Mod Shells 4⁄92.cpt / Shells / Module Shell ThC 5.0 / Shell Main.c < prev    next >
C/C++ Source or Header  |  1992-02-26  |  5KB  |  132 lines

  1. /*
  2.  *  Module Starter Main.c
  3.  *
  4.  *  This is a shell that you should use when beginning a new module.
  5.  *
  6.  *
  7.  *    This program source code and it's compiled version is
  8.  *  Copyright (c) 1991 N. Hawthorn.
  9.  *  This program source code and it's compiled version IS NOT IN THE
  10.  *  PUBLIC DOMAIN ! Please read the "COPYRIGHT NOTICE / NH" file for details
  11.  *  regarding use of this program source code and it's compiled version.
  12.  *
  13.  *  This module's name is "shell", it's type is "MOD1", it's ID is 999
  14.  *
  15.  *  SET YOUR PROJECT UP LIKE THIS!!!!
  16.  *
  17.  *  Under "Edit Menu, Options", MACHEADERS OFF!, MACSBUG OFF!,
  18.  *  REQUIRE PROTOTYPES OFF!
  19.  *
  20.  *  Under "Project Menu, Set Project Type", Attrs = 20 !!
  21.  *
  22.  *  THIS PROJECT IS SET UP CORRECTLY, MAKE SURE YOU SET ANY OTHERS YOU DO
  23.  *  THIS WAY !! IF YOU DON'T WEIRD THINGS WILL HAPPEN AND YOU WILL SPEND
  24.  *  THE REST OF YOUR LIFE LOOKING THROUGH YOUR CODE FOR SOMETHING THAT
  25.  *  AIN'T THERE.
  26.  *
  27.  *  If you don't read through "Writing MUBBS Modules" then not only are you
  28.  *  wasting MY time, you are wasting your OWN by being LAZY !
  29.  *
  30.  *  Try NOT to include MacTraps, you really don't need it.
  31.  *
  32.  *
  33.  *  This is where it all starts...
  34.  *
  35.  */
  36.  
  37. #define INMAIN
  38.  
  39. #include <SetUpA4.h>
  40. #include "MUBBS Module.h"
  41.  
  42. /* Prototypes for this file, we leave "Require Prototypes" off while developing
  43.  * but build prototypes when we are ALMOST done testing the module. This may
  44.  * catch some bugs that we missed! I use "Protoclip" a FKEY that is freeware
  45.  * and available on the Support BBS.
  46. */
  47.  
  48. pascal void main(int mode1, struct GS *G1, Ptr P1);
  49. int doshell(void);
  50.  
  51. /* my globals for this file (put your globals below)
  52.    GLOBALS ARE TRICKY ! (this is a multi line BBS)
  53. */
  54.  
  55.  
  56.  
  57. /* the following code is the "main" code. For most "normal" modules, just
  58.    change the programmers name to your own and put your code in the
  59.    "doshell" function.
  60. */
  61.  
  62. pascal void main (mode1,G1,P1) /* called from the main routines, and what mode to be in */
  63. int mode1;
  64. struct GS *G1; /* we point to the "global" struct in the Main Module here */
  65. Ptr P1; /* we ignore this pointer, we do not use it at all */
  66. {
  67. Handle temph;
  68. float version = 1.0; /* what version of MUBBS you are compatable with IE: 1.0 and above
  69.                         MAKE SURE YOU ARE COMPATABLE BEFORE SETTING THIS LESS THAN THE
  70.                         VERSION OF MUBBS YOU ARE DEVELOPING THIS FOR ! */
  71.  
  72. RememberA0(); SetUpA4(); /* This sets up the A4 register to access our globals */
  73. asm { _RecoverHandle }; asm {move.l a0,temph}; HLock(temph); /* locks our module, do this ! */
  74.  
  75. G=G1; /* This MUST be the first thing you do in main only, it sets up the struct globals */
  76. mode[u]=mode1; /* set up our mode so that you can read it anywhere */
  77.  
  78. switch (mode[u]) { /* any un-handled modes return error from this module */
  79.             /* modes are
  80.                0= Return the programmers name and the module's type & version only.
  81.                1= Bye bye call, if you returned 99 for a init call, you
  82.                   get called when the program quits with mode=1.
  83.                   You should do a "unlock" to release your module's memory space
  84.                   and unlock any memory you allocated.
  85.                2= Normal call, no pointer passed.
  86.                3= Call with a pointer to a data struct (for passing data to a module).
  87.               98= do a version check against MUBBS version.
  88.             */
  89.  
  90.     case 2:
  91.         doshell();
  92.         G->moduleresult=0;
  93.         break;
  94.     case 98:
  95.         versionck(version); /* just return after this call, don't modify anything */
  96.         break;        
  97.     case 0:
  98.         strcpy (G->programmer,"N Hawthorn"); /* show the programmer's name up to 20 chars*/
  99.         strcpy (G->modtype,"shell V1.0");     /* module type & version up to 30 chars
  100.                                                the TYPE isn't always the name! */
  101.         G->moduleresult=0; /* if this was also a init call we need close call put 99 here */
  102.         break;
  103.     default:
  104.         G->moduleresult=1; /* return bad code */
  105.     };
  106.  
  107. HUnlock(temph); /* unlocks this module, do this ! */
  108. RestoreA4(); /* call this when you are all done */
  109. }
  110.  
  111.  
  112.  
  113. doshell() /* this is where you put all your ideas and dreams! */
  114. {
  115.  
  116. if (!G->online[u]) return; /* do this check so we can log out if they hang up */
  117.  
  118. loguser(G->modulename[u]); /* this tells where you are for remote sysop,
  119.                               or writes to a log file */
  120.  
  121. /* you print the following so that the sysop can monitor use on the mac screen 
  122.    YOU DON'T HAVE TO PRINT THIS, you can print what you wish */
  123.  
  124. print("C> Line %d %s, at: %s\n",(u+1),G->username[u],G->modulename[u]);
  125. send("C> Line %d %s, at: %s]",(u+1),G->username[u],G->modulename[u]);
  126.  
  127.  
  128. /* start your code here..... */
  129.  
  130.  
  131. }
  132.